<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body th:fragment="tooth_function">
<div class="wonderful-top">

    <div class="top-list top-list-one">
        <div onclick="mytext('zx')">
            <a class="write-artical" href="javascript:;" target="_self">
                <img src="/icon/icon_Questions.png" alt="有贝口腔网">
                <span>写文章</span>
            </a>
        </div>
        <div onclick="mytext('wd')">
            <a href="javascript:;" target="_self" id="qa">
                <img src="/icon/icon_Articles.png" alt="有贝口腔网">
                <span>提问题</span>
            </a>
        </div>
    </div>
    <div class="top-list top-list-two">
        <div>
            <a href="javascript:;" target="_self" onclick="showPlanFun()">
                <img src="/icon/Dentist.png" alt="有贝口腔网">
                <span>网上看牙</span>
            </a>
        </div>
        <div>
            <a href="http://www.hasbei.com/about/link" target="_blank">
                <img src="/icon/Factory.png" alt="有贝口腔网">
                <span>厂家入驻</span>
            </a>
        </div>
        <div>
            <a href="http://www.hasbei.com/about/link" target="_blank">
                <img src="/icon/Hospital.png" alt="有贝口腔网">
                <span>诊所入驻</span>
            </a>
        </div>
    </div>
</div>


    <div th:replace="common/hasbei_text"></div>


<script th:inline="javascript">

    window.myauto = [[${auto}]];
</script>

<script>

    function showPlanFun() {
        layer.msg("功能即将开放，敬请期待，欢迎关注有贝口腔网！");
        //alert("功能即将开放，敬请期待，欢迎关注有贝口腔网！");
    }
    var userId=[[${loginUserId}]];
    function mytext(v) {

        console.log(userId);
        if(userId){
            $("#form-title").text("");

            if(v=="zx"){
                zx();
            }else if(v=="wd"){
                qa();
            }
        }else{
            window.location.href="/login";
        }
    }

    function  qa() {
        $("#form-title").val("");
        $("#form-title").attr("placeholder","请输入口腔问题（5-100个汉字）以?号结尾")
        editor.txt.html('<p id="myplaceholder" style="color: #999">【非必填】，描述该口腔问题背景，如什么情况下产生这个问题</p>')

        layer.open({
            title: "發表口腔问题"
            , content: $('#mytext')
            , type: 1
            , area: ["auto", "auto"]
            , anim: 5
            , btn: ['yes', 'no']
            ,yes: function(index, layero){
                var title=$("#form-title").val();
                var content=editor.txt.text();

                if(title.length <= 5 && content.length <=100 && (content.indexOf('?')==-1)){
                    layer.msg("提问的字数必须是5个字以上？结尾");
                    return false;
                }

                var questionAudit = {};

                if(content == '【非必填】，描述该口腔问题背景，如什么情况下产生这个问题'){
                    questionAudit = {
                        qcontent:title,//问题
                        quserId:userId
                    }
                }else{
                    content = editor.txt.html();
                    questionAudit = {
                        qcontent:title,//问题
                        qabstract:content,//问题背景
                        quserId:userId
                    };
                }

                $.ajax({
                    //请求方式
                    type: "POST",
                    //请求的媒体类型
                    contentType: "application/json;charset=UTF-8",
                    //请求地址
                    url: "/questionAudit/add",
                    //数据，json字符串
                    data: JSON.stringify(questionAudit),
                    //请求成功
                    success: function (result) {
                        console.log(result);
                        console.log(questionAudit);
                        if(result.boo){
                            layer.msg("上传成功,正在审核中！");

                        }else{
                            layer.msg("上传失败,请重试！");
                        }
                    },
                    //请求失败，包含具体的错误信息
                    error: function (e) {
                        console.log(e.status);
                        console.log(e.responseText);
                        layer.msg("功能异常请稍后重试！");
                    }
                });

                layer.closeAll();

            }
            ,btn2: function(index, layero){
                //按钮【按钮二】的回调
                //return false 开启该代码可禁止点击该按钮关闭
            }
        });
    }


    function zx() {
        $("#form-title").val("");
        $("#form-title").attr("placeholder","请输入文章标题（5-100个汉字）")
        editor.txt.html('<p id="myplaceholder" style="color: #999">请输入相关口腔文章、资讯内容</p>')
        //$("#myplaceholder").text("请输入相关口腔文章、资讯内容")
        layer.open({
            title: "發表文章"
            , content: $('#mytext')
            , type: 1
            , area: ["auto", "auto"]
            , anim: 5
            , btn: ['yes', 'no']
            ,yes: function(index, layero){
                var title=$("#form-title").val();
                var content=editor.txt.text();


                if(title.length <= 5 && title.length <=100){
                    layer.msg("文章标题（5-100个汉字）");
                    return false;
                }
                if(editor.txt.text().length <= 50){
                    layer.msg("文章内容至少输入50字数");
                    return false;
                }

                /*$.post(basePath+"login/out",function(data){
                    console.log(data)
                    if(data=='ok'){
                        layer.msg("退出成功");
                        location.reload();
                    }else{
                        layer.msg("退出失败");
                    }
                });*/

                //layer.closeAll(); //疯狂模式，关闭所有层
            }
            ,btn2: function(index, layero){

            }
        });
    }

</script>

</body>
</html>